import numpy as np
from matplotlib import pyplot as plt

def fun():
    plt.rcParams['font.sans-serif'] = ['SimHei']  # 用于正常显示中文标签
    plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
    # 获取x坐标
    epoch = np.linspace(0, 20, 21,endpoint=True)
    print(epoch)
    acc =  np.array([0.5465,0.7367,0.8131,0.8478,0.8704,0.8864,0.8973,0.9058,0.9156,0.9204,
                     0.9264,0.9322,0.9365,0.9393,0.9418,0.9456,0.9471,0.9508,0.9517,0.9550,
                     0.9551
                     ])
    loss = np.array([1.2424,0.7655,0.6238,0.5036,0.4084,0.3612,0.3106,0.3298,0.2606,0.2353,
                     0.2035,0.2061,0.1732,0.1759,0.1521,0.1680,0.1231,0.1235,0.1137,0.1115,
                     0.0934
                     ])
    plt.plot(epoch, acc, "r-", lw=2.5, label="准确率")
    plt.plot(epoch, loss, "b-", lw=2.5, label="loss值/10000")
    plt.title("训练误差和准确率随迭代次数变化情况")
    plt.xlabel("迭代次数")
    # plt.ylabel("y轴")
    plt.legend()
    ax = plt.gca()  # 获取当前图表，get current axis
    plt.xticks([0,2,4,6,8,10,12,14,16,18,20])
    # plt.xticks([-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi], [r'$-\pi$', r'$-\pi/2$', r'$0$', r'$+\pi/2$', r'$+\pi$'])
    plt.yticks([ 0., 0.2,0.4,0.6,0.8,1.,1.2,1.4])
    ax.spines['right'].set_color('none')  # 把右边的边界设置为不可见
    ax.spines['top'].set_color('none')  # 把上边的边界设置为不可见
    ax.xaxis.set_ticks_position('bottom')  # x轴坐标显示在下边
    # ax.spines['bottom'].set_position(('data', 0))  # 把下边界移到0点
    ax.yaxis.set_ticks_position('left')  # y轴坐标显示在左边
    # ax.spines['left'].set_position(('data', 0))  # 把右边界移到0点
    plt.show()
if __name__ == '__main__':
    fun()
